package com.jdrx.sw.sewage.api.web;

import com.jdrx.platform.commons.rest.beans.vo.ResponseVO;
import com.jdrx.platform.commons.rest.exception.BizException;
import com.jdrx.platform.commons.rest.factory.ResponseFactory2;
import com.jdrx.sw.sewage.beans.dto.AlarmRespUsersDTO;
import com.jdrx.sw.sewage.beans.dto.AlarmTypeSetDTO;
import com.jdrx.sw.sewage.beans.vo.AlarmRespUserVO;
import com.jdrx.sw.sewage.beans.vo.AlarmTypeSetVO;
import com.jdrx.sw.sewage.common.constant.Constant;
import com.jdrx.sw.sewage.service.AlarmRespUserServiceImpl;
import com.jdrx.sw.sewage.service.AlarmTypeSetServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping(value = "/api/alarmtypeset")
@Api(value = "告警类型设置")
public class AlarmTypeSetApi {

    @Autowired
    private AlarmTypeSetServiceImpl alarmTypeSetServiceImpl;
    @Autowired
    private AlarmRespUserServiceImpl alarmRespUserServiceImpl;

    @ApiOperation(value = "告警类型设置列表")
    @RequestMapping(value = "selectList", method = RequestMethod.POST)
    public ResponseVO<List<AlarmTypeSetVO>> selectList(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                       @RequestHeader(Constant.TENANT_ID) String tenantId) {
        return ResponseFactory2.ok(alarmTypeSetServiceImpl.selectList());
    }

    @ApiOperation(value = "告警类型设置开关")
    @RequestMapping(value = "updateAlarmTypeSetSwitchById", method = RequestMethod.POST)
    public ResponseVO updateAlarmTypeSetSwitchById(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                   @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                   @RequestBody AlarmTypeSetDTO alarmTypeSetDTO) throws BizException {
        return alarmTypeSetServiceImpl.updateAlarmTypeSetSwitchById(alarmTypeSetDTO);
    }


    @ApiOperation(value = "告警责任人设置列表")
    @RequestMapping(value = "selectAlarmRespUserSetList", method = RequestMethod.POST)
    public ResponseVO<List<AlarmRespUserVO>> selectAlarmRespUserSetList(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                                        @RequestHeader(Constant.TENANT_ID) String tenantId) {
        return ResponseFactory2.ok(alarmRespUserServiceImpl.selectAlarmRespUserSetList());
    }

    @ApiOperation(value = "告警责任人设置")
    @RequestMapping(value = "alarmRespUserSet", method = RequestMethod.POST)
    public ResponseVO<List<AlarmRespUserVO>> alarmRespUserSet(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                              @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                              @RequestBody @Valid AlarmRespUsersDTO dto) {
        alarmRespUserServiceImpl.alarmRespUserSet(dto.getAlarmRespUsers());
        return ResponseFactory2.ok();
    }
}
